package fr.umlv.m2.jee.spij.service.training;

import fr.umlv.m2.jee.spij.persistence.schooling.Training;
import org.springframework.stereotype.Component;

import java.io.Serializable;

/**
 * Provides methods to retrieve training into databases from DAO.
 *
 * @author lounes
 */
@Component("trainingBean")
public class DisplayTraining implements Serializable {


    /**
     * training primary key never display, use to retrieve the training in database
     */
    private long id;

    /**
     * name of training
     */
    private String name;

    /**
     * nomber year of training
     */
    private int nbYear;
    /**
     * Empty constructor
     */
    public DisplayTraining() {
    }
    /**
     * Constructs a DTO training from training.
     * @param training the training that is displayed
     */
    public DisplayTraining(Training training) {
        if (training != null)
            storeData(training);
    }
    /**
     * Stores datas from training into DisplayTraining.
     *
     * @param training the training that is displayed.
     */
    private void storeData(Training training) {
        if (training.getId() != 0L) {
            setId(training.getId());
        }
        if (!training.getName().isEmpty()) {
            setName(training.getName());
        }
        if (training.getNbYear() != 0) {
            setNbYear(training.getNbYear());
        }
    }

    /**
     * 
     * @param id the id to set
     */
    public void setId(long id) {
        this.id = id;
    }
    /**
     * 
     * @return the id of training
     */
    public long getId() {
        return id;
    }
    /**
     * 
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }
    /**
     * 
     * @return the name of training
     */
    public String getName() {
        return name;
    }
    /**
     * 
     * @param nbYear the number of year to set
     */
    public void setNbYear(int nbYear) {
        this.nbYear = nbYear;
    }
    /**
     * 
     * @return the number of year
     */
    public int getNbYear() {
        return nbYear;
    }

    @Override
    public String toString() {
        return this.name;
    }


}
